#include <stdio.h>
#include "mpi.h"
#include "dtypes.h" /* include for tests */

#define COUNT 5

int main(int argc, char **argv)
{
    int i, blocklengths[COUNT];
    MPI_Aint displacements[COUNT];
    MPI_Datatype types[COUNT], newtype;

    int size;
    MPI_Aint ext, ub, lb;

    MPI_Init(&argc, &argv);
    
    /**********************************
     * direct test of MPI_Type_struct *
     *********************************/
    for (i = 0; i < COUNT; i++)
    {
        blocklengths[i] = 1;
        displacements[i] = i;

        switch (i % 5)
        {
            case 0:
                types[i] = MPI_INT;
                break;
            case 1:
                types[i] = MPI_CHAR;
                break;
            case 2:
                types[i] = MPI_FLOAT;
                break;
            case 3:
                types[i] = MPI_DOUBLE;
                break;
            default:
                types[i] = MPI_UB;
                break;
        }
    }

    MPI_Type_struct(COUNT, blocklengths, displacements,
            types, &newtype);

    TEST_print_type(newtype);

    /* additional tests */
    MPI_Type_size(newtype, &size);
    MPI_Type_extent(newtype, &ext);
    MPI_Type_lb(newtype, &lb);
    MPI_Type_ub(newtype, &ub);

    fputs("Results:\n", stderr);

    fprintf(stderr, "size: %d, extent: %d\nlb: %d, ub: %d\n", 
            size, ext, lb, ub);

    MPI_Finalize();

    return(0);
}

